package com.timeserver.netty.chapter1;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by zhaoyong on 16/5/1.
 */
public class TimeServer {
    public static void main(String[] args) {
        int port = 8080;
        Socket socket = null;
        if (args != null && args.length > 0) {
            port = Integer.valueOf(args[0]);
        }
        ServerSocket server = null;
        try {
            server = new ServerSocket(port);
            socket = server.accept();
            try {
                Thread.currentThread().sleep(20000);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            new Thread(new TimeServerHandler(socket)).start();

        } catch (IOException e) {
        } finally {
            if (server == null) {
                try {
                    server.close();
                } catch (IOException e) {
                }
                server = null;
            }
        }
    }
}
